﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Telerik.Web.UI;
using _WebShared.Classes;

namespace KPIS.GERP.ESS.APP.App_UI.UserControls
{
    public partial class DatePicker : System.Web.UI.UserControl
    {
        //private bool _AutoPostBack = false;

        private void Page_Load(object sender, EventArgs e)
        {
            //if (_AutoPostBack)
            //{
            //    //txtDate.Attributes.Add("ontextchanged", Page.ClientScript.GetPostBackEventReference(Page, ""));
            //}
        }

        public void SetValue(object date)
        {
            if (date == null)
            {
                txtDate.Value = "";
                return;
            }

            switch (date.GetType().ToString())
            {
                case "System.DateTime":
                    txtDate.Value = ((DateTime)date).ToShortDateString();
                    break;
                case "System.String":
                default:
                    txtDate.Value = date.ToString();
                    break;
            }
        }

        public string GetStringValue()
        {
            string strDate = txtDate.Value;

            return strDate;
        }

        public Nullable<DateTime> GetDateValue()
        {
            DateTime date;

            if (DateTime.TryParse(txtDate.Value, out date))
            {
                return date;
            }
            else
            {
                return null;
            }
        }

        public HtmlInputText GetTextControl()
        {
            return txtDate;
        }

        public HtmlImage GetButtonControl()
        {
            return imgCalendar;
        }

        public string TextBoxClientId
        {
            get { return txtDate.ClientID; }
        }
        
        public string TextBoxCustomClientChange
        {
            get { return txtDate.Attributes["onchange"]; }
            set { txtDate.Attributes["onchange"] = txtDate.Attributes["onchange"] + "; " + value; }
        }

        //# region Properties

        //public bool AutoPostBack
        //{

        //    get { return _AutoPostBack; }

        //    set { _AutoPostBack = value; }

        //}

        //#endregion Properties
    }
}